package com.backstage.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 定义接口的信息
     * @return
     */
    public ApiInfo getApiInfo(){
        return new ApiInfoBuilder().title("操作员工接口的文档说明")
                .description("可以实现员工的添加、删除 、修改、查询等")
                .contact(new Contact("sakura","http://www.baidu.com","1008611@qq.com"))
                .termsOfServiceUrl("http://www.baidu.com")
                .license("sakura")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket getDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.backstage"))
                .paths(PathSelectors.regex("/error").negate())
                .paths(PathSelectors.any())
                .build();
    }
}
